/**
 * 
 */
package com.toncen.samepms.job;

import java.util.Vector;

import org.quartz.JobExecutionContext;

import com.toncen.samepms.common.AbstractJob;
import com.toncen.samepms.system.dao.ConfigurationDao;
import com.toncen.samepms.system.dao.OperatingLogDao;
import com.toncen.samepms.system.domain.OperatingLog;

/**
 * 操作日志任务
 * 
 * @author tch
 * 
 */
public class OperatingLogJob extends AbstractJob {
	/**
	 * 
	 */
	private volatile static Vector<OperatingLog> operatingLogs = new Vector<OperatingLog>(5);

	/**
	 * 
	 */
	public OperatingLogJob() {
	}

	/**
	 * @param e
	 * @return
	 * @see java.util.List#add(java.lang.Object)
	 */
	public static boolean addOperatingLog(OperatingLog operatingLog) {
		String enableOperatingLog = "2";
		try {
			enableOperatingLog = new ConfigurationDao().getValueByName("enable_operating_log");
		} catch (Exception e) {
			e.printStackTrace();
		}
		if ("1".equalsIgnoreCase(enableOperatingLog)) {
			return operatingLogs.add(operatingLog);
		} else {
			return false;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.toncen.samepms.common.AbstractJob#run(org.quartz.JobExecutionContext)
	 */
	@Override
	protected void run(JobExecutionContext context) {
		OperatingLogDao operatingLogDao = new OperatingLogDao();
		try {
			OperatingLog operatingLog;
			while (operatingLogs != null && operatingLogs.size() >= 1) {// 
				operatingLog = operatingLogs.get(0);
				operatingLogDao.add(operatingLog);
				operatingLogs.remove(0);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}
}
